import 'package:base_router_helper/base_router_helper.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

/**
 *
 * @ProjectName:    base_router_helper
 * @ClassName:      main
 * @Description:    dart类作用描述
 * @Author:         孙浩
 * @QQ:             243280864
 * @CreateDate:     2020/11/22 10:45 PM
 */
void main() => runApp(Main());

class Main extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final FluroRouter router = FluroRouter();
    BaseRouterInit.initRouterInit([PageRouter()], router);
    NavigationUtil.initRouter(router);
    App.fluroRouter = router;
    return MaterialApp(
      home: Page1(),
      onGenerateRoute: App.fluroRouter.generator,
    );
  }
}

class App {
  static FluroRouter fluroRouter;
}

class PageRouter extends BaseRouter {
  static const String page1 = "/page1";
  static const String page2 = "/page2";
  static const String page3 = "/page3";
  static const String page4 = "/page4";

  @override
  initRouterPage(FluroRouter router) {
    router.define(page1, handler: Handler(handlerFunc: (c, params) {
      return Page1();
    }));
    router.define(page2, handler: Handler(handlerFunc: (c, params) {
      return Page2();
    }));
    router.define(page3, handler: Handler(handlerFunc: (c, params) {
      return Page3();
    }));
    router.define(page4, handler: Handler(handlerFunc: (c, params) {
      return Page4();
    }));
  }
}

class Page1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: MaterialButton(onPressed: (){
          NavigationUtil.push2page(context, PageRouter.page2);
        },child: Text("page1"),),
      ),
    );
  }
}

class Page2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: MaterialButton(onPressed: (){
          NavigationUtil.push2page(context, PageRouter.page3);
        },child: Text("page2"),),
      ),
    );
  }
}

class Page3 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: MaterialButton(onPressed: (){
          NavigationUtil.push2page(context, PageRouter.page4);
        },child: Text("page3"),),
      ),
    );
  }
}

class Page4 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: MaterialButton(onPressed: (){
          NavigationUtil.pop(context);
        },child: Text("page4"),),
      ),
    );
  }
}
